package reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @ClassName Demo01
 * @Description TODO
 * 测试java.lang.Class对象的获取方式
 * @Author liang
 * @Date 2018/10/17 15:52
 * @Version 1.0
 **/
public class Demo01 {
    public static void main(String [] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException {
        String path = "reflection.User";
        Class<?> clazz = Class.forName(path);
        String name = clazz.getName();//类的名字
        String simpleName= clazz.getSimpleName();
        System.out.println(simpleName);
        //获得属性
        //Field id = clazz.getField("id");//获得public的属性
        Field id1 = clazz.getDeclaredField("id");//获得所有的属性
        System.out.println("=="+id1);
        //获取方法信息
        Method[] declaredMethods = clazz.getDeclaredMethods();
        for(Method method:declaredMethods){
            System.out.println(method);
        }
        //获取构造方法信息
        Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
        for(Constructor constructor:declaredConstructors){
            System.out.println(constructor);
        }
        Constructor<?> declaredConstructor = clazz.getDeclaredConstructor(null);
        System.out.println(declaredConstructor);


    }
}
